package com.hengxinguotong.hxgtwygsp.ui.newView.maintenanceFund;

import android.content.res.Resources;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hengxinguotong.hxgtwygsp.R;
import com.hengxinguotong.hxgtwygsp.model.UnpaidHouse;
import com.hengxinguotong.hxgtwygsp.model.Year;
import com.hengxinguotong.hxgtwygsp.ui.base.BaseDialogActivity;
import com.hengxinguotong.hxgtwygsp.ui.maintenance.unpaid.UnpaidHouseAdapter;
import com.hengxinguotong.hxgtwygsp.widget.DropListPW;
import com.hengxinguotong.hxgtwygsp.widget.RingView;
import com.hengxinguotong.hxgtwygsp.widget.YearPW;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 专项维修资金交存使用
 * Created by CS-Yong
 * 2019/9/2  4:21
 */
public class MaintenanceFundActivity extends BaseDialogActivity implements
        DropListPW.OnClickCallback<Year> {
    @BindView(R.id.mRingView)
    RingView mRingView;
    @BindView(R.id.tv_in_rate)
    TextView mTvInRate;
    @BindView(R.id.tv_house_num)
    TextView mTvHouseNum;
    @BindView(R.id.tv_paid_num)
    TextView mTvPaidNum;
    @BindView(R.id.tv_unpaid_num)
    TextView mTvUnpaidNum;
    @BindView(R.id.ring_view_container)
    LinearLayout mRingViewContainer;
    @BindView(R.id.unpaid_house_no)
    TextView mUnpaidHouseNo;
    @BindView(R.id.unpaid_recycler)
    RecyclerView mUnpaidRecycler;
    @BindView(R.id.tv_img_title)
    TextView mTvImgTitle;
    @BindView(R.id.member_close)
    ImageView mMemberClose;
    @BindView(R.id.no_pay_building)
    TextView mNoPayBuilding;
    @BindView(R.id.no_pay_building_container)
    RelativeLayout mNoPayBuildingContainer;

    private List<Year> yearList;
    private List<UnpaidHouse> unpaidHouseList = new ArrayList<>(),
    showHouseList = new ArrayList<>();
    private UnpaidHouseAdapter unpaidHouseAdapter;

    @Override
    public int getLayoutResId() {
        return R.layout.activity_maintenance_fund;
    }


    @Override
    public void init() {
        yearList = new ArrayList<>();
        Year year;
        for (int i = 0; i <= 6; i++) {
            year = new Year();
            year.setName(i == 0 ? "全部" : i + "栋");
            year.setValue(i);
            yearList.add(year);
        }
        mockView();
        unpaidHouseAdapter = new UnpaidHouseAdapter(R.layout.item_unpaid_house, showHouseList);
        GridLayoutManager glm = new GridLayoutManager(this, 5, LinearLayoutManager.VERTICAL, false);
        mUnpaidRecycler.setLayoutManager(glm);
        mUnpaidRecycler.setAdapter(unpaidHouseAdapter);
    }

    private void mockView() {
        Resources resources = getResources();
        int[] colors = {resources.getColor(R.color.c5353FF), resources.getColor(R.color.c19A4FF)};
        mRingView.setColors(colors);
        float[] values = {14, 86};
        mRingView.setValues(values);

        unpaidHouseList.add(new UnpaidHouse("1栋1单元1层4室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋1单元3层1室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋1单元3层4室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋1单元4层1室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋1单元4层2室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋1单元5层1室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋2单元2层1室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋2单元2层2室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋2单元4层1室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋2单元4层2室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋2单元5层1室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋2单元6层2室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋2单元9层3室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋2单元10层2室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋3单元1层3室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋3单元2层3室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋3单元9层1室", 1));
        unpaidHouseList.add(new UnpaidHouse("1栋3单元10层1室", 1));

        unpaidHouseList.add(new UnpaidHouse("2栋1单元1层1室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋1单元1层2室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋1单元1层3室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋1单元1层4室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋1单元1层5室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋1单元1层12室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋1单元5层1室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋1单元13层2室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋1单元16层1室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋1单元17层1室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋1单元20层1室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋1单元24层3室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋1单元29层3室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋1单元30层1室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋2单元4层1室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋2单元5层2室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋2单元6层2室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋2单元7层1室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋2单元8层1室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋2单元10层3室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋2单元12层1室", 2));
        unpaidHouseList.add(new UnpaidHouse("2栋2单元18层3室", 2));

        unpaidHouseList.add(new UnpaidHouse("3栋2单元6层1室", 3));
        unpaidHouseList.add(new UnpaidHouse("3栋2单元7层1室", 3));

        unpaidHouseList.add(new UnpaidHouse("4栋1单元4层1室", 4));
        unpaidHouseList.add(new UnpaidHouse("4栋1单元6层1室", 4));
        unpaidHouseList.add(new UnpaidHouse("4栋2单元2层1室", 4));
        unpaidHouseList.add(new UnpaidHouse("4栋2单元5层1室", 4));

        unpaidHouseList.add(new UnpaidHouse("5B栋/单元1层1室", 5));
        unpaidHouseList.add(new UnpaidHouse("5B栋/单元1层12室", 5));
        unpaidHouseList.add(new UnpaidHouse("5B栋/单元2层3室", 5));
        unpaidHouseList.add(new UnpaidHouse("5B栋/单元3层1室", 5));
        unpaidHouseList.add(new UnpaidHouse("5A栋/单元3层2室", 5));
        unpaidHouseList.add(new UnpaidHouse("5B栋/单元4层1室", 5));
        unpaidHouseList.add(new UnpaidHouse("5A栋/单元4层3室", 5));
        unpaidHouseList.add(new UnpaidHouse("5A栋/单元6层2室", 5));
        unpaidHouseList.add(new UnpaidHouse("5A栋/单元6层3室", 5));
        unpaidHouseList.add(new UnpaidHouse("5A栋/单元7层1室", 5));
        unpaidHouseList.add(new UnpaidHouse("5B栋/单元7层2室", 5));
        unpaidHouseList.add(new UnpaidHouse("5A栋/单元7层2室", 5));
        unpaidHouseList.add(new UnpaidHouse("5A栋/单元7层3室", 5));
        unpaidHouseList.add(new UnpaidHouse("5B栋/单元8层3室", 5));
        unpaidHouseList.add(new UnpaidHouse("5A栋/单元9层1室", 5));
        unpaidHouseList.add(new UnpaidHouse("5A栋/单元9层2室", 5));
        unpaidHouseList.add(new UnpaidHouse("5A栋/单元9层3室", 5));
        unpaidHouseList.add(new UnpaidHouse("5B栋/单元10层2室", 5));
        unpaidHouseList.add(new UnpaidHouse("5A栋/单元11层2室", 5));
        unpaidHouseList.add(new UnpaidHouse("5B栋/单元12层1室", 5));
        unpaidHouseList.add(new UnpaidHouse("5A栋/单元12层2室", 5));
        unpaidHouseList.add(new UnpaidHouse("5B栋/单元14层1室", 5));
        unpaidHouseList.add(new UnpaidHouse("5B栋/单元14层3室", 5));
        unpaidHouseList.add(new UnpaidHouse("5A栋/单元15层2室", 5));
        unpaidHouseList.add(new UnpaidHouse("5B栋/单元15层2室", 5));
        unpaidHouseList.add(new UnpaidHouse("5A栋/单元16层2室", 5));
        unpaidHouseList.add(new UnpaidHouse("5B栋/单元17层1室", 5));
        unpaidHouseList.add(new UnpaidHouse("5A栋/单元22层1室", 5));
        unpaidHouseList.add(new UnpaidHouse("5B栋/单元24层3室", 5));


        unpaidHouseList.add(new UnpaidHouse("6栋1单元1层12室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元3层4室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元4层4室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元5层3室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元8层1室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元9层1室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元10层1室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元10层3室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元12层1室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元12层3室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元13层1室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元15层1室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元16层1室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元20层2室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元21层2室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元23层2室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元24层2室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元24层3室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元24层4室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元26层3室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元27层3室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元29层2室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元31层1室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋1单元31层2室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋2单元6层2室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋2单元14层2室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋2单元14层4室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋2单元16层3室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋2单元17层3室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋2单元17层4室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋2单元18层2室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋2单元18层3室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋2单元19层1室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋2单元24层2室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋2单元25层4室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋2单元26层3室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋2单元26层4室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋2单元27层2室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋2单元28层3室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋2单元31层1室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋3单元2层3室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋3单元7层1室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋3单元8层3室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋3单元9层3室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋3单元11层3室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋3单元14层1室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋3单元15层1室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋3单元16层1室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋3单元16层3室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋3单元18层1室", 6));
        unpaidHouseList.add(new UnpaidHouse("6栋3单元28层3室", 6));

        showHouseList.addAll(unpaidHouseList);
    }

    @OnClick(R.id.member_close)
    public void onViewClicked() {
        finish();
    }


    @OnClick(R.id.no_pay_building_container)
    public void onViewClicked(View view) {
        YearPW yearPW = new YearPW(this, view.getWidth());
        yearPW.setOnClickCallback(this);
        yearPW.initData(yearList, 0);
        yearPW.showAsDropDown(view);
    }

    @Override
    public void onClickPW(Year year) {
        mNoPayBuilding.setText(year.getName());

        showHouseList.clear();
        int no = year.getValue();
        if (no == 0){
            showHouseList.addAll(unpaidHouseList);
        }else {
            for (UnpaidHouse house: unpaidHouseList) {
                int houseNo = house.getNo();
                if (houseNo == no){
                    showHouseList.add(house);
                }
            }
        }
        unpaidHouseAdapter.notifyDataSetChanged();
    }
}
